package com.gu.controller;

import com.gu.service.OssService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * Description:
 *
 *
 * @Autor: Rolin
 * datetime: 05-19-14:32
 */
@RestController
@RequestMapping("/eduOss")
@CrossOrigin
@Api(tags = "文件上传")
public class OssController {

    @Resource
    private OssService ossService;

    @PostMapping("/upload")
    @ApiOperation(value = "文件上传")
    public CommonResult uploadFile(MultipartFile file) {
        String filePath = ossService.uploadFile(file);
        return !StringUtils.isEmpty(filePath) ? CommonResult.success().data("filePath", filePath) : CommonResult.error();
    }

    @ApiOperation(value = "删除云端文件")
    @DeleteMapping("/deleteByUrl")
    public CommonResult deleteByUrl(@RequestParam("coverName") String coverName){
       boolean result =  ossService.deleteByUrl(coverName);
       return result ? CommonResult.success() : CommonResult.error();
    }

}
